package cn.hzking.gjmall.adpters.coupon;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;
import java.util.Locale;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.bean.CouponBean;
import cn.hzking.gjmall.utils.FormatUtil;
import cn.hzking.gjmall.utils.UIUtils;

/**
 * Created by Administrator on 2018/4/16.
 */

public class CouponListAdapter extends BaseQuickAdapter<CouponBean.DataBean.CouponSkuIdsArrayBean.CouponBean1,BaseViewHolder> {
    public CouponListAdapter(@Nullable List<CouponBean.DataBean.CouponSkuIdsArrayBean.CouponBean1> data) {
        super(R.layout.item_coupon,data);
    }
    private CouponInterface couponInterface;

    public CouponInterface getCouponInterface() {
        return couponInterface;
    }

    public void setCouponInterface(CouponInterface couponInterface) {
        this.couponInterface = couponInterface;
    }

    @Override
    protected void convert(BaseViewHolder helper, final CouponBean.DataBean.CouponSkuIdsArrayBean.CouponBean1 item) {
        TextView tvPrice = helper.getView(R.id.coupon_price);
        TextView tvFanWei = helper.getView(R.id.coupon_fanwei);
        TextView tvName = helper.getView(R.id.coupon_name);
        TextView tvLimit = helper.getView(R.id.coupon_limit);
        TextView tvTime = helper.getView(R.id.coupon_time);
        TextView userTv = helper.getView(R.id.coupon_user);
        tvPrice.setText(String.valueOf(item.getFaceValue()));//价格
        final int position=helper.getLayoutPosition();
        if(item.getEnoughMoney() == 0){//限制条件
            tvLimit.setText("无金额门槛");
        }else {
            tvLimit.setText(String.format(Locale.CHINA,"满¥%s可用",String.valueOf(item.getEnoughMoney())));
        }
        userTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                couponInterface.select(item.getCouponId(), FormatUtil.format(item.getFaceValue())+"元优惠券",position);
            }
        });
        //优惠券名称
        tvName.setText(String.valueOf(item.getName()));
        //使用范围
        if("ALL".equals(item.getCouponItemType())){
            tvFanWei.setText("全场通用");
        }else {
            tvFanWei.setText("指定专区使用");
        }
        String start = UIUtils.formatTime(item.getBeginTime());
        String end = UIUtils.formatTime(item.getEndTime());
        tvTime.setText(start+"/"+end);
    }

    public interface  CouponInterface{
        public void select(int couponId,String couponName,int position);
    }
}
